//
//  AppIconVC.swift
//  HLDesktop
//
//  Created by 黄龙 on 2023/9/4.
//

import UIKit
import Photos

class AppIconVC: UIViewController {
    let leftWidth = 80.0
    let workViewWidth = screen_W - 80
    let workViewTop = 140.0 //present窗口，高度不一定是screen_H
    // 懒加载
    lazy var collectView: UICollectionView = {
                // FlowLayout自定义设置
        let layout = UICollectionViewFlowLayout.init()
            // 设置item的排列方式 ( horizontal , vertical)
        layout.scrollDirection = .vertical
                // 设置item的size
        let backW = screen_W - self.leftWidth
//        let itemW = backW / 5
//        layout.itemSize = CGSize(width:itemW , height: itemW)
//            // 列间距
//        layout.minimumLineSpacing = 5
//            // 行间距
//        layout.minimumInteritemSpacing = 5
//        // 设置item的四边边距（四边边距不是每个item的内缩边距，而是外间隔连距，所以计算item大小时，还要将边距计算在内减掉边距后，再算item大小）
//        layout.sectionInset = UIEdgeInsets.init(top: 5, left: 5, bottom: 5, right: 5)
//        // 设置页头尺寸
//        layout.headerReferenceSize = CGSize(width: backW, height: 44)
//
//        // 设置页尾尺寸
//        layout.footerReferenceSize = CGSize(width: backW, height: 0)
        
        // 初始化
        let collectview = UICollectionView.init(frame: CGRect(x: 0, y: 0, width: workViewWidth, height: screen_H-workViewTop), collectionViewLayout: layout)
            // 设置背景颜色
        collectview.backgroundColor = .systemBackground
        // 设置代理对象
        collectview.delegate = self
        // 设置数据源对象
        collectview.dataSource = self
        collectview.showsVerticalScrollIndicator = true
            // 设置垂直滚动是否滚到item的最底部
        collectview.alwaysBounceVertical = true
            // 设置水平滚动是否滚到item的最右边
//        collectview.alwaysBounceHorizontal = true
            // 开启uicollectionView的分页显示效果
        collectview.isPagingEnabled = false //与scrollview的分页类似,分页滑动，还是平滑
        
        // 注册Cell
        collectview.register(IconSelectionCell.self, forCellWithReuseIdentifier: "IconSelectionCell")

        // 注册Hearder
        collectview.register(SectionHeader.self, forSupplementaryViewOfKind:UICollectionView.elementKindSectionHeader, withReuseIdentifier: "headerIdentifier")
        
        // 注册footer
        collectview.register(UICollectionReusableView.self, forSupplementaryViewOfKind:UICollectionView.elementKindSectionFooter, withReuseIdentifier: "footIdentifier")
        
        return collectview
     }()
    
    lazy var leftBar: UIView = {
        let leftview = UIView()
        leftview.backgroundColor = .secondarySystemGroupedBackground.withAlphaComponent(0.25)
        leftview.layer.cornerRadius = 10
        return leftview
    }()
    
    lazy var workBar: UIView = {
        let view = UIView()
        return view
    }()
    
    lazy var scrollview: UIScrollView = {
        let scroll = UIScrollView()
        scroll.isScrollEnabled = true
        scroll.isPagingEnabled = false
        return scroll
    }()
    
    lazy var albumAlertView:UIView = {
        let aView = UIView()
        return aView
    }()
    
    lazy var albumImgView: UIImageView = {
        let imgView = UIImageView()
        imgView.layer.cornerRadius = 10
        imgView.clipsToBounds = true
        return imgView
    }()
    
    lazy var btnCheckPhoto: UIButton = {
        let btn = UIButton()
        btn.setTitleColor(.label, for: .normal)
        btn.titleLabel?.font = .systemFont(ofSize: 18)
        return btn
    }()
    
    var albumPhotoUrl:String?
    
    
    let icoSections:[String] = ["通信","天气","工具","设备","相机","游戏","连接","交通","人体","自然","媒体","键盘","商业","时钟",
                       "健康","健身","索引","数学"]
    let imgSections:[String] = ["message","cloud.sun","folder","display","camera","gamecontroller","antenna.radiowaves.left.and.right",
                                "car","person","ant","repeat","command","cart","timer","heart","figure.run","a.circle","x.squareroot"]
    var icoMCList:[[String]] = []
    
    var clockTimer:Timer?
    var timeCount = 5
    
    public var selectNewIcoBlock:((_ icoName:String)->Void)?
    
    deinit {
        print("没有循环引用才会触发:AppIconVC.deinit")
        cancelTimer()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .systemGroupedBackground
        
        // Do any additional setup after loading the view.
        self.initUI()
        self.initData()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.collectView.reloadData()
    }
    
    override func viewDidLayoutSubviews() {
        let viewHeight = self.view.bounds.height
        self.leftBar.frame = CGRect(x: 0, y: workViewTop, width: leftWidth, height: viewHeight - workViewTop)
        self.scrollview.frame = CGRect(x: 0, y: 0, width: leftWidth, height: viewHeight - workViewTop)
        
        self.workBar.frame = CGRect(x: leftWidth, y: workViewTop, width: workViewWidth, height: viewHeight - workViewTop)
        collectView.frame = CGRect(x: 0, y: 0, width: workViewWidth, height: viewHeight - workViewTop)
    }

    func initUI(){
        let topView = UIView(frame: CGRect(x: 0, y: 0, width: screen_W, height: 60))
        view.addSubview(topView)
        let label = UILabel(frame: CGRect(x: 0, y: 0, width: screen_W, height: 48))
        topView.addSubview(label)
        label.text = "选择快捷图标"
        label.font = .boldSystemFont(ofSize: 16)
        label.textColor = .label
        label.textAlignment = .center
        let cancelBtn = UIButton(frame: CGRect(x: screen_W - 15 - 50, y: 0, width: 50, height: 48))
        topView.addSubview(cancelBtn)
        cancelBtn.setTitle("取消", for: .normal)
        cancelBtn.setTitleColor(prjTitleColor, for: .normal)
        cancelBtn.titleLabel?.font = .boldSystemFont(ofSize: 16)
        cancelBtn.addActionWithBlock { [weak self](sender) in
            Vibrations.light.vibrate()
//            self?.cancelTimer()
            self?.dismiss(animated: true)
        }
        
        
        view.addSubview(self.leftBar)
        self.leftBar.addSubview(self.scrollview)
        
        
        var iTop = 0.0
        for i in 0 ..< icoSections.count{
            let btn = UIButton(frame: CGRect(x: 0, y: iTop, width: leftWidth, height: 60))
            self.scrollview.addSubview(btn)
            btn.setTitle(icoSections[i], for: .normal)
            btn.setTitleColor(.secondaryLabel, for: .normal)
            btn.titleLabel?.font = .systemFont(ofSize: 14)
            btn.setImage(UIImage(systemName: imgSections[i]), for: .normal)
            btn.tag = i+1
            btn.addActionWithBlock { [weak self](sender) in //凡是添加到View上的控件的block，不管会不会触发都得用weakself，否则不会deinit
                self?.onSelectSectionTab(sender.tag-1)
            }
            iTop += 60.0
        }
        self.scrollview.contentSize = CGSize(width: leftWidth, height: iTop)
        
        view.addSubview(self.workBar)
        workBar.addSubview(self.collectView)
        
        let btnWidth = screen_W-60
        let albumBtn = ProfileButton(frame: CGRect(x: 30, y: 80, width: btnWidth, height: 42))
        view.addSubview(albumBtn)
        albumBtn.setTitle("  从手机相册选择", for: .normal)
        albumBtn.setImage(UIImage(named: "albumBtn@2x.png"), for: .normal)
        albumBtn.setTitleColor(prjTitleColor, for: .normal)
//        albumBtn.layer.cornerRadius = 6
        albumBtn.easyRoundRect(corner: [.topLeft,.topRight], radii: CGSize(width: 6, height: 6))
        albumBtn.backgroundColor = prjTitleColor.withAlphaComponent(0.75)
        albumBtn.layer.borderColor = UIColor.white.withAlphaComponent(0.5).cgColor
        albumBtn.addActionWithBlock { [weak self](sender) in
            if let btn = sender as? ProfileButton{
                btn.animateTouchUpInside {
                    self?.showAlbumSelector()
                }
            }
        }
        
        view.insertSubview(self.albumAlertView, belowSubview: albumBtn)
        albumAlertView.frame = CGRect(x: 30, y: 80+41, width: btnWidth, height: 1)
        albumAlertView.clipsToBounds = true
        albumAlertView.backgroundColor = prjTitleColor.withAlphaComponent(0.75)

        
        albumAlertView.addSubview(self.albumImgView)
        albumImgView.frame = CGRect(x: btnWidth/2.0 - 32, y: 25, width: 64, height: 64)
        
        albumAlertView.addSubview(self.btnCheckPhoto)
        btnCheckPhoto.frame = CGRect(x: btnWidth/2.0 - 75, y: 115, width: 150, height: 36)
        btnCheckPhoto.addActionWithBlock {[weak self](sender) in
            self?.selectAlbumPhoto()
        }
        btnCheckPhoto.setTitle(String(format: "确定%d", timeCount), for: .normal)
        btnCheckPhoto.backgroundColor =  prjTitleColor
        btnCheckPhoto.layer.cornerRadius = 18
    }
    
    func initData(){
        var tmpArr:[String] = []
        tmpArr.append(contentsOf: SF_TX.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_TQ.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_WTYGJ.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_SB.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_XJZP.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_YX.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_LJ.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_JT.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_RT.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_ZR.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_MT.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_JP.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_SY.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_SZ.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_JK.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_JS.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_SUOY.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
        
        tmpArr.removeAll()
        tmpArr.append(contentsOf: SF_SX.SFList.map({ "\($0)" }))
        icoMCList.append(tmpArr)
    }
    
    func onSelectSectionTab(_ index:Int){
        self.collectView.scrollToItem(at: IndexPath(row: 0, section: index), at: .centeredVertically, animated: true)
    }
    
    
}

//MARK: - 从相册中选择图片，并截取区域做为图标
extension AppIconVC:UIImagePickerControllerDelegate & UINavigationControllerDelegate{
    func showAlbumSelector(){
        if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
            PHPhotoLibrary.requestAuthorization { (status) in
                switch status {
                case .authorized: self.presentPhotoPickerController()
                case .notDetermined:
                    if status == PHAuthorizationStatus.authorized {
                        self.presentPhotoPickerController()
                    }
                case .denied:
                    let alert = UIAlertController(title: "没有权限获取照片信息", message: "照片权限已被拒绝，请开启权限后再选择照片", preferredStyle: .alert)
                    let confirmAction = UIAlertAction(title: "去设置", style: .default, handler: { (goSettingAction) in
                        DispatchQueue.main.async {
                            let url = URL(string: UIApplication.openSettingsURLString)!
                            UIApplication.shared.open(url, options: [:])
                        }
                    })
                    let cancelAction = UIAlertAction(title: "取消", style: .cancel)
                    alert.addAction(confirmAction)
                    alert.addAction(cancelAction)
                    self.present(alert, animated: true)
                case .restricted: let alert = UIAlertController(title: "权限限制", message: "照片的获取被限制了无法获取", preferredStyle: .alert)
                    let okAction = UIAlertAction(title: "好的", style: .default)
                    alert.addAction(okAction)
                    self.present(alert, animated: true)
                default: break
                }
            }
        }
        
    }
    
    func selectAlbumPhoto(){
        self.cancelTimer()
        self.dismiss(animated: true)
        if albumPhotoUrl != nil && !albumPhotoUrl!.isEmpty{
            self.selectNewIcoBlock?(albumPhotoUrl!)
        }
    }
    
    func presentPhotoPickerController() {
        DispatchQueue.main.async {
            let myPickerController = UIImagePickerController()
            myPickerController.allowsEditing = true
            myPickerController.delegate = self
            myPickerController.sourceType = .photoLibrary
            self.present(myPickerController, animated: true, completion: nil)
        }
    }
    
    /* ----- UIImagePickerControllerDelegate ----- */
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        var imgData:UIImage?
        if let image = info[UIImagePickerController.InfoKey.editedImage] as? UIImage {
            imgData = image
            self.albumImgView.image = image //allowsEditing = true时走这里,image为截取的图像，不是整个图像
        } else if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
            imgData = image
            self.albumImgView.image = image//否则走这里,image为整张图片
        }
        var imageurl = ""
        if let imgUrl = info[.imageURL] as? NSURL{
            imageurl = imgUrl.absoluteString!
//            print("\(imageurl)")
            if !imageurl.isEmpty && imgData != nil{
                let md5key = "aiScreen.pCache." + imageurl.hl_md5()
                if imageurl.lowercased().hasSuffix(".png"){
                    if let imageSaveData = NSData(contentsOf: imgUrl as URL){
                        self.albumPhotoUrl = imageurl
                        if imageSaveData.count <= 5120000{
                            UserDefaults.standard.set(imageSaveData, forKey: md5key)
                            UserDefaults.standard.synchronize()
                        }
                        self.startTimer()
                        dismiss(animated: true, completion: nil)
                        return
                    }
                }
                if let imageSaveData = imgData!.jpegData(compressionQuality: 0.2){
                    self.albumPhotoUrl = imageurl
                    if imageSaveData.count <= 5120000{
                        UserDefaults.standard.set(imageSaveData, forKey: md5key)
                        UserDefaults.standard.synchronize()
                    }
                    self.startTimer()
                }
            }
        }else if let mediaURL = info[.mediaURL] as? NSURL{//直接拍摄的照片?
            imageurl = mediaURL.absoluteString!
            print("\(imageurl)")
            self.albumPhotoUrl = imageurl
            self.startTimer()
        }
//mediaURL:
//file:///private/var/mobile/Containers/Data/Application/A604C48D-4565-4F9C-83E0-F5C80D11BE3D/tmp/33E083F4-3CA1-4A59-AC26-61AFD5190B9F.png
        dismiss(animated: true, completion: nil)
    }
    
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        dismiss(animated: true, completion: nil)
    }
    
    func updateTime() {
        if (timeCount <= 0){
            cancelTimer()
            UIView.animate(withDuration: 0.25, delay: 0.25,options: [.curveEaseInOut,.allowUserInteraction]) {[weak self] in
                self?.albumAlertView.frame = CGRect(x: 30, y: 80+41, width: screen_W-60, height: 1)
            }
        }
        self.btnCheckPhoto.setTitle(String(format: "确定%d", timeCount), for: .normal)
        timeCount -= 1
    }
    
    func startTimer() {
        self.cancelTimer()

        if clockTimer==nil {
            timeCount = 5
            clockTimer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true, block: { [weak self](timer) in
                self?.updateTime() //用block写法，且用weak self，则关闭时即使用timer未释放，也能deinit，然后可以在deinit里释放timer。用下面的selector方式则不行
            })
//            Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateTime), userInfo: nil, repeats: true)
            if let curTimer: Timer = clockTimer {
                RunLoop.main.add(curTimer, forMode: .common)
                curTimer.fire() //马上触发，不然显示会慢1秒
            }
            
            UIView.animate(withDuration: 0.25, delay: 0.25,options: [.curveEaseInOut,.allowUserInteraction]) {[weak self] in
                self?.albumAlertView.frame = CGRect(x: 30, y: 80+41, width: screen_W-60, height: 170)
            } completion: { [weak self](_) in
                self?.albumAlertView.easyRoundRect(corner: [.bottomLeft,.bottomRight], radii: CGSize(width: 10, height: 10))
            }
        }
    }
    
    func cancelTimer() {
        if clockTimer != nil {
            clockTimer?.invalidate()
            clockTimer = nil
        }
    }
    
}


extension AppIconVC: UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//        print("响应点击事件\(indexPath.section)-\(indexPath.row)")
        Vibrations.selection.vibrate()
        if icoMCList.count>indexPath.section{
            let tmpArr = icoMCList[indexPath.section]
            if tmpArr.count > indexPath.row{
                self.cancelTimer()
                self.dismiss(animated: true)
                let icoName = tmpArr[indexPath.row]
                self.selectNewIcoBlock?(icoName)
                
            }
        }
        
    }
    
    //    MARK: - 是否高亮
      func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool{
          return true //true才能触发didSelectItemAt点击事件
      }
      
//      //    MARK: - 高亮颜色
//      func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath){
//          let cell = collectionView .cellForItem(at: indexPath)
//          cell?.backgroundColor = prjTitleColor.withAlphaComponent(0.25)
//      }
//      
//      //    MARK: - 取消长按颜色
//      func collectionView(_ collectionView: UICollectionView, didUnhighlightItemAt indexPath: IndexPath){
//          let cell = collectionView .cellForItem(at: indexPath)
//          cell?.backgroundColor = .systemBackground
//      }
}

extension AppIconVC: UICollectionViewDataSource{
        // 设置组数
        func numberOfSections(in collectionView: UICollectionView) -> Int {
            return self.icoSections.count
        }
    
        // 设置每组item个数
        func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
            if icoMCList.count>section{
                return self.icoMCList[section].count
            }else{
                return 0
            }
        }
    
        // 注册cell
        func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
            let cellString = "IconSelectionCell"
            if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellString, for: indexPath) as? IconSelectionCell{
                let tmpArr = icoMCList[indexPath.section]
                let tmpName = tmpArr[indexPath.row]
                cell.updateCellImg(systemImgName: tmpName)
                return cell
            }else{
                return UICollectionViewCell()
            }
        }
    
    
//MARK: - 设定header和footer的方法，根据kind不同进行不同的判断即可
        func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
            if kind == UICollectionView.elementKindSectionHeader{
                if let headerV = collectionView .dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "headerIdentifier", for: indexPath) as? SectionHeader{
//                    headerV.backgroundColor = .secondarySystemGroupedBackground
                    headerV.sectionHeaderlabel.text = icoSections[indexPath.section]
                    return headerV
                }
            }else if kind == UICollectionView.elementKindSectionFooter{
                let footerV = collectionView .dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "footIdentifier", for: indexPath)
                footerV.backgroundColor = .tertiarySystemGroupedBackground
                return footerV
            }
            return UICollectionReusableView.init()
        }
    
}

/*
 静态设置item大小等：
let layout = UICollectionViewFlowLayout.init()
layout.itemSize = CGSize(width:itemW , height: itemW)
    // 列间距
layout.minimumLineSpacing = 1
    // 行间距
layout.minimumInteritemSpacing = 1
// 设置item的四边边距
layout.sectionInset = UIEdgeInsets.init(top: 5, left: 5, bottom: 5, right: 5)

而如果要动态设置item的大小、间距等，则需要重写代理
 */
extension AppIconVC : UICollectionViewDelegateFlowLayout{
    //    MARK: - item Size
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let iCount = collectionView.frame.width >= 300 ? 5.0 : 4.0
        let width = collectionView.frame.width / iCount
        return CGSize(width: width, height: width)
    }
    
//     //     MARK: - 边框距离
//    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
//        return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) //改由cell内部去处理间距
//    }
    
    //    MARK: - 行最小间距
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }
    
    //    MARK: - 列最小间距
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }

    
    //    MARK: - headerView 高
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        return CGSize (width: collectionView.bounds.width, height: 40)
    }
    
    //    MARK: - footerView 高
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
        return CGSize (width: collectionView.bounds.width, height: 0)
    }
    
    
}

class SectionHeader: UICollectionReusableView {
    lazy var sectionHeaderlabel: UILabel = {
        let label = UILabel()
        label.textColor = .secondaryLabel
        label.font = .systemFont(ofSize: 14)
        return label
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(sectionHeaderlabel)
        sectionHeaderlabel.frame = CGRect(x: 15, y: 0, width: self.bounds.width-30, height: self.bounds.height)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
